package org.example.demo;

import java.util.Random;
import java.util.Scanner;

/*
*  发票系统,
* 
* */
public class Test4 {
    public static void  main(String[] args){
        // 创建中奖号码随机 6 + 1数字
        int[] resArr = new int[7];
        resArr = getResult(resArr);

        for (int i = 0; i < resArr.length; i++) {
            System.out.println(resArr[i]);
        }
        // 键入用户的 6+1
        int[] userArr = new int[7];
        userArr = getUser(userArr);

        int redCount =   getConfirmRedAndBlue(resArr,userArr,true);
        int BlueCount =   getConfirmRedAndBlue(resArr,userArr,false);
        System.out.println(redCount);
        System.out.println(BlueCount);
        // 匹配奖池
    }
    public static  int getConfirmRedAndBlue(int[] resArr,int[] userArr,Boolean bool){
        int count = 0;
        if(bool){
            for (int i = 0; i < resArr.length -1 ; i++) {
                if(contains(resArr, userArr[i])){
                    count+=1;
                }
            }
        }else{
            if(resArr[resArr.length-1]  == userArr[userArr.length-1]){
                count++;
            }
        }
        return  count;
    }
    public static int[] getResult(int[] arr){
        // 创建六个
        for (int i = 0; i < arr.length -1;) {
            int res = new Random().nextInt(33) +1;
            if(!contains(arr,res)){
                arr[i] =   res;
                i++;
            }
        }
        // 创建一个
        arr[arr.length-1] = new Random().nextInt(16)+1;
        return arr;
    }
    public static int[] getUser(int[] arr){
        Scanner scanner =  new Scanner(System.in);
        for (int i = 0; i < arr.length-1;) {
            int inEnter =   scanner.nextInt();
            if(!contains(arr,inEnter)){
                arr[i] = inEnter;
                i++;
            }else {
                System.out.println("已经存在的值,不允许输入");
            }
        }
        arr[arr.length-1] = scanner.nextInt(16);
        return  arr;
    }
    public static Boolean contains(int[] arr, int i){
        Boolean flag = false;
        for (int i1 = 0; i1 < arr.length; i1++) {
            if(arr[i1] == i){
                flag = true;
            }
        }
        return  flag;
    }

}